package com.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.base.BaseDao;
import com.bean.RulerInfo;
import com.bean.RulerRole;
import com.util.GUtil;

public class RightDao extends BaseDao {
	
	public String getRights(int roleId,int rulerid) throws Exception{
		Session session = super.getSession();
		Query query = session.createQuery("From RulerRole r where r.roleid=:roleId and r.rulerid=:rulerid");
		query.setInteger("roleId", roleId);
		query.setInteger("rulerid", rulerid);
		RulerRole rulerRole = (RulerRole) query.uniqueResult();
		if(rulerRole!=null){
			return rulerRole.getRulerWord();
		}
		return null;
	}
	
	//检查数据库中是否拥有该actionName
	public String checkAction(String actionName, String methodName, Long roleId){
		Session session = super.getSession();
		String sql = "From RulerInfo where url like :action ";
		Query query = session.createQuery(sql);
		query.setString("action", "/"+actionName+"%");
		
		RulerInfo rulerInfo = (RulerInfo) query.uniqueResult();
		
		if(rulerInfo!=null){
			return GUtil.SUCCESS;
		}else
			return GUtil.NULL;
	}
}

